package ar.edu.utn.frre.sistop.simumem.fragments;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import ar.edu.utn.frre.sistop.simumem.R;
import ar.edu.utn.frre.sistop.simumem.model.Particion;

public class PartitionAdapter extends BaseAdapter {
	
	private ArrayList<Particion> mData;
	private LayoutInflater mInflater = null;
	
	static class ViewHolder {
		TextView tvIdParticion;
		TextView tvInicio;
		TextView tvTamano;
	}
	
	public PartitionAdapter(Context c, ArrayList<Particion> d) {
		this.mData = d;
		mInflater = LayoutInflater.from(c);
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_partition, parent, false);
			holder = new ViewHolder();
			holder.tvIdParticion = (TextView) convertView.findViewById(R.id.itemPartition_idParticion);
			holder.tvInicio = (TextView) convertView.findViewById(R.id.itemPartition_inicio);
			holder.tvTamano = (TextView) convertView.findViewById(R.id.itemPartition_tamano);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.tvIdParticion.setText(String.valueOf(mData.get(position).getId()));
		holder.tvInicio.setText(String.valueOf(mData.get(position).getInicio()));
		holder.tvTamano.setText(String.valueOf(mData.get(position).getTamano()));
		return convertView;
	}

}
